package cn.xuguowen.user.designPatten.strategy.prod;

import java.util.Objects;

/**
 * ClassName: PayChannelEnum
 * Package: cn.xuguowen.user.designPatten.strategy.prod
 * Description:
 * 支付渠道枚举类——定义了项目中全部的支付渠道
 * @Author 徐国文
 * @Create 2023/4/28 18:38
 * @Version 1.0
 */
public enum PayChannelEnum {

    ZFB_PAY(1,"支付宝"),
    WX_PAY(2,"微信"),
    BANK_PAY(3,"银行卡");

    private Integer code;
    private String desc;

    PayChannelEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    /**
     * 获取指定的枚举对象
     * @param code
     * @return
     */
    public static PayChannelEnum getByCode(Integer code) {
        if (Objects.isNull(code)) {
            throw new IllegalArgumentException("参数异常！");
        }

        PayChannelEnum[] values = PayChannelEnum.values();
        for (PayChannelEnum value : values) {
            if (code.equals(value.code)) {
                return value;
            }
        }

        return null;
    }
}
